package listbyorder.access001_100.test12;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/6 14:35
 */
public class Solution1 {

    // 解法一： 300斩中比较牛逼的解法
    public String intToRoman(int num) {
        String res = "";
        int count = 0;
        while (num != 0) {
            int cur = num % 10;
            res = getRes(cur, count) + res;
            count++;
            num /= 10;
        }
        return res;
    }

    private String getRes(int num, int count) {
        char[] tens = {'I', 'X', 'C', 'M'};
        char[] fives = {'V', 'L', 'D'};
        String res = "";
        if (num <= 3) {
            while (num != 0) {
                res += tens[count];
                num--;
            }
        }
        if (num == 4) {
            res += (tens[count] + "") + (fives[count] + "");
        }
        if (num == 5) {
            res += fives[count] + "";
        }
        if (num > 5 && num < 9) {
            res += fives[count];
            num -= 5;
            while (num != 0) {
                res += tens[count];
                num--;
            }
        }
        if (num == 9) {
            res += (tens[count] + "") + (tens[count + 1] + "");
        }
        return res;
    }
}
